package com.smartx.app;

import android.app.Application;
import android.content.Context;

import com.smartx.Network;
import com.smartx.core.Wallet;
import com.smartx.util.ResourceUtil;

public class SatApp extends Application{
    private Context context;
    private int coinbaseIndex;
    private String coinbaseAddress;
    private Network network;
    private Wallet wallet = null;
    private static SatApp _INSTANCE;

    @Override
    public void onCreate() {
        super.onCreate();
        _INSTANCE = this;
        ResourceUtil.init(this,BuildConfig.DEBUG);
    }

    public void setContext(Context context){
        this.context = context;
    }

    public Context getContext(){
        return this.context;
    }

    //TODO:判断wallet是否被锁住，如果被锁住则要求输入密码
    public void setCoinBase(int index){
        this.coinbaseIndex = index;
        this.coinbaseAddress = wallet.getAccount(index).toAddressString();
    }

    public int getCoinBase(){
        return this.coinbaseIndex;
    }

    public void setNetwork(Network network){
        this.network = network;
    }

    public final Network getNetwork(){
        return this.network;
    }

    //设置当前应用程序的钱包，并且锁住钱包
    public void setWallet(Wallet wallet){
        this.wallet = wallet;
    }

    public final Wallet getWallet(){
        return this.wallet;
    }

    //coinbase address只能被获取，不能被设置
    public final String getCoinBaseAddress(){
        return this.coinbaseAddress;
    }

    public static SatApp getInstance() {
        return _INSTANCE;
    }
}
